#ifndef COMMON_H
#define COMMON_H

#include <QtCore>
#include <QObject>

template <class T>
class Singleton
{
public:
    static T& getInstance()
    {
        static T instance;
        return instance;
    }
};

template <class Interface, class Implementation>
class IocSingleton
{
public:
    static Interface& getInstance()
    {
        static Implementation& instance;
        return static_cast<Interface>(instance);
    }
};

class PropertyChanged : public QObject
{
    Q_OBJECT
public:
signals:
    void propertyChanged();
    void propertyReleased();
};

template <class T>
class Property : public PropertyChanged
{
protected:
    T   _value;
public:
    explicit Property(){}

    Property(T value)
    {
        _value = value;
    }

    ~Property()
    {
        emit propertyReleased();
    }

    const T& getValue()
    {
        return _value;
    }

    void setValue(T value)
    {
        this->_value = value;
        emit propertyChanged();
    }

    operator T() const
    {
        return this->_value;
    }

    Property<T>& operator=(T& value)
    {
        this->setValue(value);
        return *this;
    }
};

#endif // COMMON_H
